{extend name="default/base/base_fuwu" /}
{block name="fuwu_main"}
<div class="dssc-form-default">
    <form method="post" enctype="multipart/form-data" id="my_store_form" onsubmit="ds_ajaxpost('my_store_form','url','{:url('fuwu_manage_info/base')}');return false;"  >

        <dl>
            <dt>{$Think.lang.fuwu_manage_organization_name_text[$o2o_fuwu_organization_info.o2o_fuwu_organization_type]}：</dt>
            <dd>
                <input type="text" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_name}" name="organization_name" class="text w400">
            </dd>
        </dl>

        <dl>
            <dt>头像{$Think.lang.ds_colon} </dt>
            <dd>
                <div class="dssc-upload-thumb store-avatar">
                    <p>
                        <img src="{notempty name='o2o_fuwu_organization_info.o2o_fuwu_organization_avatar'}{:get_o2o_fuwu_file($o2o_fuwu_organization_info.o2o_fuwu_organization_id,$o2o_fuwu_organization_info.o2o_fuwu_organization_avatar,'avatar')}{/notempty}" id="img_file" />
                    </p>
                </div>
                <div class="dssc-upload-btn"> 
                    <a href="javascript:void(0);">
                        <span><input type="file" hidefocus="true" size="1" class="input-file" name="file" id="file" /></span>
                        <p><i class="iconfont">&#xe733;</i>图片上传</p>
                    </a>
                </div>
            </dd>
        </dl>
        
        <dl>
            <dt>联系电话{$Think.lang.ds_colon}</dt>
            <dd>
                <input class="text w200" name="organization_phone" maxlength="20" type="text"  id="organization_phone" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_phone}" />
            </dd>
        </dl>
        <dl>
            <dt>{$Think.lang.fuwu_manage_organization_birthday_text[$o2o_fuwu_organization_info.o2o_fuwu_organization_type]}{$Think.lang.ds_colon}</dt>
            <dd>
                <p>
                    <input class="text w200" id='organization_birthday' name="organization_birthday" type="text"  value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_birthday|date='Y-m-d',###}" />
                </p>
                <p class="hint"></p>
            </dd>
        </dl>
        <dl>
            <dt>所在地区{$Think.lang.ds_colon}</dt>
            <dd>
                <span class="w400">
                    <div onclick="change_map()">
                        <input name="organization_lng" id="longitude" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_lng}" type="hidden" />
                        <input name="organization_lat" id="latitude" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_lat}" type="hidden" />
                        <input type="hidden" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_city_id|default=''}" name="organization_city_id" id="_area_1">
                        <input type="hidden" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_region_id|default=''}" name="organization_region_id" id="_area">
                        <input type="hidden" name="organization_region_name" id="region" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_region_name|default=''}"/>
                    </div>
                </span>
            </dd>
        </dl>
        <dl>
            <dt>详细地址{$Think.lang.ds_colon}</dt>
            <dd>
                <input type="text" value="{$o2o_fuwu_organization_info.o2o_fuwu_organization_address}" name="organization_address" class="text w400" onkeyup="local.search($(this).val());">
                <div id="allmap" style="width:530px;height: 350px;margin-top: 20px"></div>
            </dd>
        </dl>
        <div class="bottom">
            <input type="submit" class="submit" value="{$Think.lang.ds_common_button_save}" />
        </div>
    </form>
</div>

<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/ajaxfileupload.js"></script> 
<script src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js"></script>
<script type="text/javascript" src="{$Think.HTTP_TYPE}api.map.baidu.com/api?v=2.0&ak={$baidu_ak}"></script>
<script>
var local;
    var map;
    var lst_name='';

    function change_map(){
        var name=$("#region").val();

        if(name!='' && lst_name!=name){
            lst_name=name;
            map.setCurrentCity(name);
            map.centerAndZoom(name,16);
            map.clearOverlays();
            local.search(name);
        }

    }
    $(function(){

        map = new BMap.Map("allmap");
        var lng = '{$o2o_fuwu_organization_info.o2o_fuwu_organization_lng}';
        var lat = '{$o2o_fuwu_organization_info.o2o_fuwu_organization_lat}';
        if(!lng && !lat){
            var geolocation = new BMap.Geolocation();
            geolocation.getCurrentPosition(function (r) {
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                    var lng = r.point.lng;
                    var lat = r.point.lat;
                    var point = new BMap.Point(lng, lat);
                    map.centerAndZoom(point, 16);
                    map.addControl(new BMap.NavigationControl());
                    map.enableScrollWheelZoom();
                    var marker = new BMap.Marker(point);  // 创建标注
                    map.addOverlay(marker);              // 将标注添加到地图中
                    marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
                    document.getElementById("longitude").value = lng;
                    document.getElementById("latitude").value = lat;

                } else {
                    layer.msg('failed' + this.getStatus());
                }
            }, {enableHighAccuracy: true})
        }else{
            var point = new BMap.Point(lng, lat);
            map.centerAndZoom(point, 16);
            map.addControl(new BMap.NavigationControl());
            map.enableScrollWheelZoom();
            var marker = new BMap.Marker(point);  // 创建标注
            map.addOverlay(marker);              // 将标注添加到地图中
            marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
        }


        var options = {
            onSearchComplete: function(results){
                // 判断状态是否正确
                if (local.getStatus() == BMAP_STATUS_SUCCESS){
                    if(results.getCurrentNumPois()>0){

                        map.clearOverlays();  //清除标注  或者可以把market 放入数组
                        var point = new BMap.Point(results.getPoi(0).point.lng , results.getPoi(0).point.lat);
                        var marker = new BMap.Marker(point);
                        map.centerAndZoom(point, 16);
                        map.addOverlay(marker);
                        marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画

                        document.getElementById("longitude").value = results.getPoi(0).point.lng;
                        document.getElementById("latitude").value = results.getPoi(0).point.lat;

                    }
                }
            }
        };
        local = new BMap.LocalSearch(map, options);
        map.addEventListener("click", function(e){
//                    alert(e.point.lng + ", " + e.point.lat);
            map.clearOverlays();  //清除标注  或者可以把market 放入数组
            var point = new BMap.Point(e.point.lng , e.point.lat);
            var marker = new BMap.Marker(point);
            map.addOverlay(marker);
            marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画

            document.getElementById("longitude").value = e.point.lng;
            document.getElementById("latitude").value = e.point.lat;
        });
    })
    $(function () {
        $('#organization_birthday').datepicker({dateFormat: 'yy-mm-dd'});
        $("#region").ds_region();
        var url = '{:url("fuwu_manage_info/upload_info_file")}';
        $('#my_store_form').find('input[type="file"]').unbind().change(function () {
            var id = $(this).attr('id');
            ajaxFileUpload(url, id);
        });
    });

    function ajaxFileUpload(url, id)
    {
        $(document).off('change', "#file").on('change', function () {
            $.ajaxFileUpload({
                url: url,
                secureuri: false,
                fileElementId: id,
                dataType: 'json',
                data: {type: 'avatar'},
                success: function (data)
                {
                    if (data.code!=10000) {
                        layer.msg(data.message)
                    } else {
                        $("#img_" + id).attr('src', data.result.url);
                    }
                },
                error: function (data, status, e)
                {
                    console.error(data);
                }
            })
            return false;
        });
    }
</script>    


{/block}
